All files / Bandstand/src/app/(band)/setlists/[id]/edit page.tsx

0% Statements 0/81
0% Branches 0/1
0% Functions 0/1
0% Lines 0/81

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82                                                                                                                                                                   
export const dynamic = 'force-dynamic'

import {notFound} from 'next/navigation'
import {prisma} from '@/lib/db'
import {pageSession} from '@/lib/guard'
import {getSetlist} from '@/lib/setlists'
import {detectKey, parseChordPro} from '@/lib/chordpro'
import {displayName} from '@/lib/songs'
import SetlistEditor, {
  type Item,
  type PickSong,
} from '@/components/SetlistEditor'

export const metadata = {title: 'Setlist'}

export default async function SetlistPage({params}: {params: {id: string}}) {
  const {band, isAdmin} = await pageSession()
  const set = await getSetlist(params.id, band.id)
  if (!set) notFound()
  const songs = await prisma.song.findMany({
    where: {bandId: band.id},
    orderBy: [{status: 'asc'}, {title: 'asc'}],
    include: {
      chartVersions: {
        orderBy: {number: 'desc'},
        take: 1,
        select: {source: true},
      },
    },
  })
  const library: PickSong[] = songs.map((s) => ({
    id: s.id,
    title: s.title,
    ready: s.status === 'READY',
    leadSinger: s.leadSinger,
    seconds: s.seconds,
    key: s.chartVersions[0]
      ? detectKey(parseChordPro(s.chartVersions[0].source))
      : null,
  }))
  return (
    <SetlistEditor
      id={set.id}
      library={library}
      initial={{
        name: set.name,
        gigDate: set.gigDate ? set.gigDate.toISOString().slice(0, 10) : '',
        startTime: set.startTime ?? '',
        venue: set.venue ?? '',
        notes: set.notes ?? '',
        items: set.items.map(
          (i): Item =>
            i.kind === 'SET'
              ? {
                  uid: i.id,
                  kind: 'SET',
                  label: i.label ?? 'Set',
                  minutes: i.minutes ? String(i.minutes) : '',
                  startTime: i.startTime ?? '',
                }
              : i.kind === 'BREAK'
                ? {
                    uid: i.id,
                    kind: 'BREAK',
                    minutes: i.minutes ? String(i.minutes) : '',
                  }
                : {
                    uid: i.id,
                    kind: 'SONG',
                    songId: i.songId ?? '',
                    note: i.note ?? '',
                    key: i.key ?? '',
                  },
        ),
      }}
      editedBy={displayName(set.updatedBy)}
      editedAt={set.updatedAt.toISOString()}
      canDelete={isAdmin}
    />
  )
}